package cn.edu.suse.epilepsy.controller;

import cn.edu.suse.epilepsy.common.BizException;
import cn.edu.suse.epilepsy.common.R;
import cn.edu.suse.epilepsy.entity.dto.SysUserLoginDto;
import cn.edu.suse.epilepsy.entity.dto.SysUserPage;
import cn.edu.suse.epilepsy.entity.dto.SysUserRegisterDto;
import cn.edu.suse.epilepsy.entity.pojo.SysUser;
import cn.edu.suse.epilepsy.entity.vo.SysUserVo;
import cn.edu.suse.epilepsy.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: QingShu
 * @Date: 2024/7/4 10:08
 */
@Controller
@ResponseBody
@RequestMapping("/sysuser")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;
    @PostMapping("/login")
    public R login(@RequestBody SysUserLoginDto dto) throws BizException {
        System.out.println("phone:" + dto.getPhone());
        System.out.println("pwd:" + dto.getPwd());
        SysUserVo sysUserVo = sysUserService.login(dto);
        if (sysUserVo == null) {
            throw new BizException("登录失败");
        }
        return R.success(sysUserVo);
    }
    @PostMapping("/register")
    public R register(@RequestBody SysUserRegisterDto dto) throws BizException{
        SysUser newUser = sysUserService.register(dto);
        return R.success(newUser);
    }
    @GetMapping("/registerss")
    public R registers(){
        SysUser sysUser = new SysUser();
        sysUser.setName("小三");
        return R.success(sysUserService.registers(sysUser));
    }
    @PostMapping("/pageLikePhone")
    public R pageLikePhone(@RequestBody SysUserPage dto){
        return null;
    }
    @DeleteMapping("/{id}")
    public R deleteById(@PathVariable Integer id){
        return null;
    }
}